<extend name="Public:iframe" />
<block name="content">
    <form class="layui-form" action="">
        <h2 class="content-title">编辑文章类型</h2>
        <table class="layui-table" lay-data="{height: 'full-100',cellMinWidth: 80, url:'{:U('Article/edit_type')}',method:'post', page:{layout: [ 'prev', 'page', 'next', 'skip', 'count']}, id:'dataTable'}" lay-filter="table">
            <thead>
            <tr>
                <th lay-data="{type:'checkbox', fixed: 'left'}" lay-filter='test'></th>
                <th lay-data="{field:'id', width:60, sort: true}">ID</th>
                <th lay-data="{field:'name', width:200,edit:true}">类型名称(<span style="color:red;">点击编辑</span>)</th>
                <th lay-data="{fixed: 'right',width:200, align:'center', toolbar: '#handle'}">操作</th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="handle">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="submit">保存</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>
    </form>
</block>

<block name="foot_script">

    <script>
        $(layui.use(['layer','form','table'], function(){
            var layer = layui.layer,form = layui.form,table = layui.table;

            table.on('tool(table)', function(obj){
                var data = obj.data;
                if(obj.event === 'submit'){
                    var url = '{:U("Article/do_edit_type")}';

                    var ids = [data.id];
                    $.post(url,data,function (res) {
                        if (res.code === 1){
                            layer.msg(res.msg);
                            table.reload('dataTable');
                        } else {
                            layer.msg(res.msg);
                        }
                    });
                }else if(obj.event === 'del'){
                    var url = '{:U("Article/del_type")}';
                    layer.confirm('真的删除吗？', function(index){
                        // 组装ID
                        var ids = [data.id];
                        $.post(url,{ids:ids,method:'del'},function (res) {
                            if (res.code === 1){
                                layer.msg(res.msg);
                                layer.close(index);
                                table.reload('dataTable');
                            } else {
                                layer.msg(res.msg);
                            }
                        });
                    });
                }
            });

        }));
    </script>
</block>